package com.april.product.controller;

import com.april.common.constant.MallUrl;
import com.april.common.utils.PageUtils;
import com.april.common.utils.Result;
import com.april.product.entity.AttrGroupEntity;
import com.april.product.model.vo.AttrGroupVo;
import com.april.product.service.AttrGroupService;
import com.april.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 属性分组
 *
 * @author april
 * @email 2673888518@qq.com
 * @date 2023-07-13 00:31:15
 */
@RestController
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @GetMapping(MallUrl.product.PRODUCT_ATTR_GROUP_LIST)
    public Result list(@RequestParam Map<String, Object> params,@PathVariable("cateLogId")Long cateLogId){
        // PageUtils page = attrGroupService.queryPage(params);
        PageUtils page = attrGroupService.queryPage(params,cateLogId);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(MallUrl.product.PRODUCT_ATTR_GROUP_INFO)
    public Result info(@PathVariable("attrGroupId") Long attrGroupId){
		AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);
        AttrGroupVo attrGroupVo =  categoryService.findCateLogPath(attrGroup);

        return Result.ok().put("attrGroup", attrGroupVo);
    }

    /**
     * 保存
     */
    @RequestMapping(MallUrl.product.PRODUCT_ATTR_GROUP_ADD)
    public Result save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.save(attrGroup);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(MallUrl.product.PRODUCT_ATTR_GROUP_UPDATE)
    public Result update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(MallUrl.product.PRODUCT_ATTR_GROUP_DELETE)
    public Result delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return Result.ok();
    }

}
